<!DOCTYPE html>
<html lang="en">
#parse('base/head.html')
<body class="no-skin">

<div class="main-container ace-save-state" id="main-container">

    <div class="fp-framework main-content padding-12-20">
        <div class="main-content-inner">
					
            <div class="page-content">
				<div class="hidden" >
					<input class="col-xs-12 col-sm-10" type="text"  id="form-field-currentYear" placeholder="currentYear" value="$!{currentYear}" />
				</div>
                <div class="row">
                	
                    <div class="col-sm-12">
						<div class="row col-md-12 fp-toolbar fpxmList" >
							<form method="POST"   id="qryForm">
							<select class="chosen-select form-control" name="vtime" id="form-select-vtime" data-placeholder="年份">
								<option value="2017">2017</option>
								<option value="2018">2018</option>
								<option value="2019">2019</option>
								<option value="2020">2020</option>
								<option value="2021">2021</option>
								<option value="2022">2022</option>
								<option value="2023">2023</option>
								<option value="2024">2024</option>
								<option value="2025">2025</option>
								<option value="2026">2026</option>
								<option value="2027">2027</option>
								<option value="2028">2028</option>
								<option value="2029">2029</option>
								<option value="2030">2030</option>
							</select>
							<select class="chosen-select form-control" name="townId" id="form-select-townId" data-placeholder="镇(乡)">
								<option value="-1">全部</option>
								#foreach($townInfoPO in $townInfoPOList)
								<option value="$!{townInfoPO.townId}">$!{townInfoPO.townName}</option>
								#end
							</select>
							<select class="chosen-select form-control" name="villageId" id="form-select-villageId" data-placeholder="行政村">
								<option value="-1">全部</option>
							</select>
							<button type="button" id="qryBtn"  class="btn btn-sm btn-primary pull-left " ><span class="ace-icon fa fa-plus icon-on-right"></span>开始统计</button>
							<button type="button" id="excelBtn"  class="btn btn-sm btn-primary pull-left " ><span class="ace-icon fa fa-download icon-on-right"></span>导出数据</button>
							</form>
						</div>


                        <div class="row">
                            <div class="col-sm-12" style="overflow-x:auto">
                                <table id="grid-list"></table>
                                <div id="grid-list-pager"></div>
                            </div>
                        </div>
                    </div>
					
                <div/>
            </div>
        </div><!-- /.page-content -->
    </div>
</div>
#parse('base/footer.html')
<script src="$!webPath/assets/js/bootbox.js"></script>
<script>
    var projectType = '';
    jQuery(function ($) {
        menuActive(2);
        
        $("#qryBtn").on('click',function () {
    		reloadGridData();
        });
    	
    	$("#excelBtn").on('click',function () {
    		console.log("excelBtn click");
        	var url = '$!webPath/jzpr/exportAidStaffRankData?';
	  		var params = $('#qryForm').serialize();
	  		params = decodeURIComponent(params,true);
	  	    params = encodeURI(encodeURI(params));
	  		url += params;
	  		console.log(params);
	  		console.log(url);
	  		var w  = window.open(url,'_blank');   
        });
    	
    	

        
        
    });
</script>
<!-- 项目列表 -->
<script type="text/javascript">
    function reloadGridData() {
		console.log("reloadGridData...");
        jQuery("#grid-list").jqGrid('setGridParam',{
            datatype:'json',
			mtype : "POST",
            postData:{'vtime':$("#form-select-vtime option:selected").val(),
                'townId':$("#form-select-townId option:selected").val(),
                'villageId':$("#form-select-villageId option:selected").val()
			}, //发送数据
            page:1
        }).trigger("reloadGrid");
    }
	
	var parentBodyHeight = $('#left-gov-tree', window.parent.document).height()||800;
    //var pkh_parent_column = $("#grid-list").closest('[class*="col-"]').closest('h4');
    var widget_header = $(".fpxmList");
	    //resize to fit page size
    $(window).on('resize.jqGrid', function () {
        $("#grid-list").jqGrid( 'setGridWidth', widget_header.width()-24 );
    });
    function detailClick_pro(channelId){
        
		//打开模态窗口
		//console.log("清空模态详情");
		$('#operateDetailModal').children().remove(); 
		//console.log("显示加载信息...");
		$('#operateDetailModal').append('<div class="modal-dialog modal-xm " ><div class="modal-content" style="height: 200px;overflow: auto;"><div class="modal-header hide"></div><div class="modal-body center " ><div style="clear:both"></div><div style="height:100px;"><div class="fp-loading"><i class="fa fa-spinner fa-pulse fa-3x"></i><p>数据加载中，请耐心等待</p></div></div></div><div class="modal-footer hide"></div></div></div>'); 
		//console.log("加载模态详情");
		$('#operateDetailModal').modal({keyboard:false,backdrop:true,remote:"$!webPath/basicData/aidReportChannelDetail?action=update&channelId="+channelId});
    };
	
	function detailClick_pro_old(projectId,editRowId){
		parent.frames[0].location.href  = "$!webPath/basicData/aidReportChannelDetail?action=update&projectId="+projectId; 
    };
	
    
    
	
    //初始化模态窗口
    jQuery(function($) {
		//v2
		$("#operateDetailModal").on("hidden", function() {  
			$(this).removeData("modal");  
			console.log("operateDetailModal hidden ");
			
		});  
		//v3
		$("#operateDetailModal").on("hidden.bs.modal", function() {  
			$(this).removeData("bs.modal");
			/*modal页面加载$()错误,由于移除缓存时加载到<span style="color: rgb(51, 51, 255);"><div class="modal-content"></div></span>未移除的数据，手动移除加载的内容*/
			$(this).find(".modal-content").children().remove(); 
			console.log("operateDetailModal hidden.bs.moda ");
		}); 
	});
	
    $("#grid-list").jqGrid({
        url : '$!webPath/jzpr/qryAidStaffRankData',
        datatype : "json",
		mtype : "POST",
        height : parentBodyHeight-300,
        //autoHeight : true,
        autowidth: true,
        colNames : [ '序号','乡镇','行政村','帮扶人','单位名称','走访次数'],
        colModel : [
            {name : 'sortNum',index : 'sortNum',width : 50},
            {name : 'townName',index : 'townName' },
            {name : 'villageName',index : 'villageName' },
            {name : 'staffName',index : 'staffName' },
            {name : 'department',index : 'department' },
            {name : 'visitedCountSum',index : 'visitedCountSum',sortable : true}
            
        ],
        postData: {    
        	'vtime':$("#form-select-vtime option:selected").val(),
            'townId':$("#form-select-townId option:selected").val(),
            'villageId':$("#form-select-villageId option:selected").val()
	    },
        jsonReader : {
            root : "resultList",
            page : "page",
            total : "totalPages",
            records : "totalRecords",
            rows : "resultList"
        },
        rowNum:10,
        rowList:[10,20,50,100],
        pager: '#grid-list-pager',
        viewrecords : true,
        loadComplete : function() {
			var table = this;
			setTimeout(function(){
				styleCheckbox(table);
				
				updateActionIcons(table);
				updatePagerIcons(table);
				enableTooltips(table);
			}, 0); 

			$(table).siblings(".norecords").remove(); 
			var rowNum = parseInt($(table).getGridParam("records"), 10);   
			if (rowNum <= 0) {   
				$(table).parent().append("<div  class=\"norecords\">没有数据...</div>");
				$(table).siblings(".norecords").show(); 								
			} 
        },

        multiselect : false
    });
    
    $("#grid-list").closest(".ui-jqgrid-bdiv").css({ "overflow-x" : "scroll" });
</script>
<script>
    jQuery(function ($) {
    	//设置下拉框
    	var currentYear = $("#form-field-currentYear").val();
    	$("#form-select-vtime").find("option[value='"+currentYear+"']").attr("selected",true);
    	
    });

    
    
    </script>
<script>
    jQuery(function ($) {
    	$("#form-select-townId").change(function () {  
            var ss = $(this).children('option:selected').val(); 
            $("#form-select-villageId").empty();
            var option = $("<option>").val("").text("全部");
            $("#form-select-villageId").append(option);
            if(""==ss){
            	
            	
            }else{
            	$.ajax({
    				type: "POST",
    				datatype:'json', 
    				url: "$!webPath/subsystem/base/villageinfo/queryVillagesByTown",
    				data: {
    					townId: ss
    				},
    				success: function (resultData) {
    					console.log(resultData);
    					//var resultVO = $.parseJSON(resultData);
    					$.grep(resultData,function(villagePO){
    						console.log(villagePO);
    						 // 实际的应用中，这里的option一般都是用循环生成多个了
    			            var option = $("<option>").val(villagePO.villageId).text(villagePO.villageName);
    			            $("#form-select-villageId").append(option);
    					});
    				},
    				error: function (data) {
    					$.msgErrorAlert("获取行政村列表时发生异常.");
    				}
    			});
            }
        });  
    	
    	
    });

</script>
</body>
</html>
